home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / HOOK.MUT < prev    next >
Text File  |  1992-11-09  |  3KB  |  81 lines

  1. ;; Hook.mut : Hook central
  2. ;; These routines let lots of routines share ME hooks.  For example, if you
  3. ;;   want foo to called from buffer-created-hook, then just
  4. ;;   (register-hook BUFFER-CREATED-HOOK "foo") and every time
  5. ;;   (buffer-created-hook) is called, (foo) will be called.
  6. ;; Notes:
  7. ;;   DO NOT defun buffer-created-hook or other hooks!  If you do, you'll
  8. ;;     ruin the party for everybody.
  9. ;;   Hooks not here:
  10. ;;     modeline-hook : Needs to be handled differently.  See modeline.mut.
  11. ;;     key-pressed-hook : Slows things down too much.  Your on your own.
  12. ;;   I define some of own hooks:  the "I" ones.  These are subsets of
  13. ;;     existing hooks that are called when a buffer is Interactive.  I do
  14. ;;     this to avoid doing a bunch of work when I don't need to.
  15. ;; C Durland 10/89    Public Domain
  16.  
  17. (include me2.h)
  18.  
  19. (list
  20.   buffer-created-list
  21.   Ibuffer-created-list        ;; interactive buffer created
  22.   file-read-list
  23.   Ifile-read-list        ;; interactive file read
  24.   enter-ME-list
  25.   leave-ME-list
  26.   process-list
  27. )
  28.  
  29. (defun
  30.   register-hook (int hook-id)(string who-u-gonna-call)
  31.   {
  32.     (switch hook-id
  33.        BUFFER-CREATED-HOOK (add-hook buffer-created-list   who-u-gonna-call)
  34.       IBUFFER-CREATED-HOOK (add-hook Ibuffer-created-list  who-u-gonna-call)
  35.        READ-FILE-HOOK       (add-hook file-read-list       who-u-gonna-call)
  36.       IREAD-FILE-HOOK       (add-hook Ifile-read-list       who-u-gonna-call)
  37.       ENTER-ME-HOOK       (add-hook enter-ME-list       who-u-gonna-call)
  38.       LEAVE-ME-HOOK       (add-hook leave-ME-list       who-u-gonna-call)
  39.       PROCESS-HOOK       (add-hook process-list       who-u-gonna-call)
  40.     )
  41.   }
  42.   enter-ME-hook        { (call-hooks enter-ME-list)       }
  43.   leave-ME-hook        { (call-hooks leave-ME-list)       }
  44.   process-hook        { (call-hooks process-list (push-args 0)) }
  45.   buffer-created-hook
  46.   {
  47.     (call-hooks buffer-created-list)
  48.     (if (!= 0 (bit-and BFInteractive (buffer-flags -1))) 
  49.     (call-hooks Ibuffer-created-list))
  50.   }
  51.   read-file-hook
  52.   {
  53.     (call-hooks file-read-list)
  54.     (if (!= 0 (bit-and BFInteractive (buffer-flags -1))) 
  55.     (call-hooks Ifile-read-list))
  56.   }
  57. )
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60. ;;;;;;;;;;;;;;;;;;;;; Gory Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62.  
  63. (defun
  64.   call-hooks (list hook-list)(hook-args) HIDDEN
  65.   {
  66.     (int j z)
  67.  
  68.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  69.       (floc (extract-element hook-list j)(push-args 1)))    ;; call the hook
  70.   }
  71.   add-hook (list hook-list) (string name) HIDDEN
  72.   {
  73.     (int j z)
  74.  
  75.     ;; Check to see if name is already registered
  76.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  77.       (if (== name (extract-element hook-list j)) (done)))
  78.     (insert-object hook-list 0 name)            ;; put name in list
  79.   }
  80. )
  81.